
package numberporting.service;

import javax.ws.rs.ConsumeMime;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.core.Response;
import numberporting.bean.Customer;
import numberporting.bean.CustomerStore;

@Path("/")
@ProduceMime("application/xml")
public class CustomerManagementService {
    
    private CustomerStore customerStore;
    
    public CustomerManagementService(CustomerStore customerStore){
        this.customerStore = customerStore;
    }
    /*
    @GET
    @Path("customers")
    public Customers getCustomers(){
        
    }*/
    @GET
    @Path("{id}")
    @ConsumeMime("application/json")
    @ProduceMime("application/json")
    public Customer getCustomerJson(@PathParam("id") String id){
        System.out.println("get customer (json)");
        customerStore.checkCustomerRS(id);
        return customerStore.getCustomer(id);
    }

    @GET
    @Path("{id}")
    @ConsumeMime("application/xml")
    @ProduceMime("application/xml")
    public Customer getCustomerXml(@PathParam("id") String id){
        System.out.println("get customer (xml)");
        customerStore.checkCustomerRS(id);
        return customerStore.getCustomer(id);
    }
            
    @PUT
    @Path("{id}")
    @ConsumeMime("application/json")
    @ProduceMime("application/json")
    public Response addCustomerJson(@PathParam("id") String id,Customer customer){
        System.out.println("adding customer to database (json)");
        customer.setId(id);
        customerStore.addCustomer(customer);
        return Response.ok().build();
    }

    @PUT
    @Path("{id}")
    @ConsumeMime("application/xml")
    @ProduceMime("application/xml")
    public Response addCustomerXml(@PathParam("id") String id,Customer customer){
        System.out.println("adding customer to database (xml)");
        customer.setId(id);
        customerStore.addCustomer(customer);
        return Response.ok().build();
    }
    
    @POST
    @Path("{id}")
    @ConsumeMime("application/json")
    @ProduceMime("application/json")
    public Response updateCustomerJson(@PathParam("id") String id,Customer customer){
        System.out.println("updating customer (json)");
        customer.setId(id);
        customerStore.updateCustomer(customer);
        return Response.ok().build();
    }

    @POST
    @Path("{id}")
    @ConsumeMime("application/xml")
    @ProduceMime("application/xml")
    public Response updateCustomerXml(@PathParam("id") String id,Customer customer){
        System.out.println("updating customer (xml)");
        customer.setId(id);
        customerStore.updateCustomer(customer);
        return Response.ok().build();
    }

    @DELETE
    @Path("{id}")
    @ConsumeMime("application/json")
    @ProduceMime("application/json")
    public Response deleteCustomerJson(@PathParam("id") String id){
        System.out.println("deleting customer from database (json)");
        customerStore.deleteCustomer(id);
        return Response.ok().build();
    }

    @DELETE
    @Path("{id}")
    @ConsumeMime("application/xml")
    @ProduceMime("application/xml")
    public Response deleteCustomerXml(@PathParam("id") String id){
        System.out.println("deleting customer from database (xml)");
        customerStore.deleteCustomer(id);
        return Response.ok().build();
    }
    
}
